#ifndef __SHIFT_REGISTER_H__
#define __SHIFT_REGISTER_H__ 1

#include <vector>

/**
 * @brief Implementation of a linear feedback shift register.
 * @author mnutzinger
 *
 * Provides a random sequence of bits calcultated by the given parameters for
 * register length, output length and feedback positions.
 */
class CShiftRegister
{
public:
	CShiftRegister();
	virtual ~CShiftRegister();

	/**
	 * Set parameters for the lfsr operation.
	 *
	 * @param pRegisterLength desired length of the shift register
	 * @param pSequenceLength desired length of the random sequence 
	 * @param pFeedback feedback positions
	 * @return error status
	 */
	bool setParameters(unsigned int pRegisterLength,
			unsigned int pSequenceLength, std::vector<unsigned int>& pFeedback);

	/**
	 * Retrieve random sequence from lfsr.
	 * @note: pSequence has to be allocated for at least mSequenceLength
	 * elements.
	 *
	 * @param pSequence reference parameter to which the random sequence is
	 * stored
	 * @return error status
	 */
	bool getRandomSequence(bool*& pSequence);

private:
	CShiftRegister(const CShiftRegister& );
	CShiftRegister& operator=(const CShiftRegister& );

	/**
	 * indicates whether the lfsr is ready for operation
	 */
	bool mReady;

	/**
	 * length of the register
	 */
	unsigned int mRegisterLength;

	/**
	 * length of the output sequence
	 */
	unsigned int mSequenceLength;

	/**
	 * feedback positions
	 */
	std::vector<int> mFeedback;

	/**
	 * the internal register
	 */
	std::vector<bool> mRegister;
};

#endif // __SHIFT_REGISTER_H__

